﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Xsl;

namespace NameMapping.CodeDom
{
    public class PreProcessor
    {
        private static readonly string xslt = "NameMapping.CodeDom.Resources.nameMapping-preParse.xslt";

        private XslCompiledTransform trans;

        public PreProcessor()
        {
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(xslt))
            {
                XmlTextReader reader = new XmlTextReader(stream);
                trans = new XslCompiledTransform();
                trans.Load(reader);
            }
        }

        public string Transform(XmlDocument doc)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            trans.Transform(doc, null, sw);

            return sb.ToString();
        }
    }
}
